///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009 Summit Contributors.  
// See: http://code.google.com/p/tyemill/wiki/SummitContributors
//
// The name and logo of Summit are trademarks of TYEMILL, LLC - All Rights 
// Reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without 
// limitation the rights to use, copy, modify, merge, publish, distribute, 
// sublicense, and/or sell copies of the Software, and to permit persons to 
// whom the Software is furnished to do so, subject to the following 
// conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
///////////////////////////////////////////////////////////////////////////////

package summit.basecamp.wrappers
{
import summit.basecamp.constants.BasecampResource;
import summit.basecamp.helpers.CategoryHelper;
import summit.data.AccountToken;
import summit.net.BasecampLoader;

/**
 * Wrapper for Basecamp category operations.
 */
public class CategoryWrapper extends AbstractWrapper implements
IStandardWrapper, IListableWrapper
{
	/** Constructor.
	 * @param token The <code>AccountToken</code> that is to be used in 
	 * identifying the Basecamp account to which API calls are made.  
	 * @param loader The <code>BasecampLoader</code> that is to be used 
	 * with all requested operations.
	 */
	public function CategoryWrapper(token:AccountToken = null, 
	loader:BasecampLoader = null)
	{
		super(BasecampResource.CATEGORY, token, loader);
	}
	
	/**
	 * Creates a new category on the server.
	 * 
	 * <p>The underlying Basecamp API requires both <code>name</code>
	 * and <code>type</code> to be specified in the XML. The 
	 * <code>type</code> should be either 'post' or 'attachment'.</p>
	 * 
	 * <p>Summit additionally requires the XML to contain
	 * a <code>project-id</code> element.</p>
	 * 
	 * @param content Represents a category.
	 */  
	public function create(content:XML):void
	{
		loader.load(CategoryHelper.create(content));
	}
	
	/**
	 * Deletes a category.
	 * 
	 * <p>Only categories without elements (elements-count == 0) can be 
	 * deleted.</p>
	 * 
	 * @param id The id of the category to be deleted.
	 */
	public function destroy(id:String):void
	{
		loader.load(CategoryHelper.destroy(id));
	}
	
	/**
	 * Gets an existing category from the Basecamp store.
	 * 
	 * <p>The XML returned is pre-filled with the existing values of 
	 * the identified category, and is ready to be resubmitted via the 
	 * <code>update</code> function.</p>
	 * 
	 * @param id The id of the category to be retrieved.
	 * @param projectId The id of the project that is to be associated 
	 * with the category.
	 * 
	 * @return A request ready for use with <code>BasecampLoader.load</code>.
	 */
	 
	public function edit(id:String, projectId:String):void
	{
		loader.load(CategoryHelper.edit(id));
	}
	
	/** Gets a list of categories for a project.
	 * <p>By default, all categories in a project are listed.</p>
	 * 
	 * @param projectId The id of the project from which 
	 * categories are to be read.  
	 */
	public function list(projectId:String):void
	{
		loader.load(CategoryHelper.list(projectId));
	}
	
	
	/**
	 * Gets a list of categories scoped by project.
	 * 
	 * 
 	 * @param projectId The id of the project from which 
	 * categories are to be read.  

	 */
	public function listByProject(projectId:String):void
	{
		loader.load(CategoryHelper.list(projectId));	
	}
	
	/**
	 * Gets a list of categories with a scoping filter.
	 * 
	 * <p>By default (not including a <code>categoryFilter</code>), all 
	 * categories in a project are listed.</p>
	 * 
	 * <p>The <code>categoryFilter</code> scopes the list to either posts
	 * or attachments</p>
	 * 
	 * @param projectId The id of the project from which 
	 * categories are to be read.  
	 * @param categoryFilter The type of categories to be read. By default, 
	 * categories of all types are returned.
	 */
	public function listWithFilter(projectId:String, 
	categoryFilter:String = null):void
	{
		loader.load(CategoryHelper.list(projectId, categoryFilter));
	}
	
	/**
	 * Retrieves a template for creating a new category.
	 * 
	 * <p>The template retrieved is used with <code>create</code> to 
	 * submit a new category.</p>
	 * 
	 * @param projectId The id of the project that is to be associated with 
	 * the category when submitted via a call to <code>create</code>.
	 */ 
	public function prepare(projectId:String):void
	{
		loader.load(CategoryHelper.prepare(projectId)); 
	}
	
	/**
	 * Gets a single category.
	 * 
	 * @param id The id of the category to be read.
	 * @param projectId The id of the project that is associated with the 
	 * category.
	 */
	public function read(id:String, projectId:String):void
	{
		loader.load(CategoryHelper.read(id));
	}
	
	/**
	 * Updates an existing category.
	 * 
	 * <p><code>content</code> submitted to <code>update</code> is typically
	 * retrieved from <code>edit</code>.</p>
	 * 
	 * @param content The updated XML content of an existing category.
	 */ 
	public function update(content:XML):void
	{
		loader.load(CategoryHelper.update(content));	
	}
}
}
//////////////////////////////////////////////////////// gmarius@tyemill.com //